package com.liefox.servicemsm.service.impl;

import com.liefox.servicemsm.service.MsmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

/**
 * @Author zjh
 * @Date 2021/7/19 下午 5:28
 **/
@Service
public class MsmServiceImpl implements MsmService {

    @Autowired
    JavaMailSenderImpl mailSender;

    @Override
    public Boolean sendMsm(String email, String fourBitRandom) {

        //邮件设置
        SimpleMailMessage message = new SimpleMailMessage();
        try {
            //主题
            message.setSubject("谷粒学院-验证码");
            //内容-验证码
            message.setText("您注册发送的验证码是：" + fourBitRandom + "   " + "三分钟之内有效！");
            //收件人
            message.setTo(email);
            //发件人
            message.setFrom("2606097218@qq.com");
            //发送
            mailSender.send(message);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
